package com.mingqijia.gassafety.console.controller;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.db.entity.WarnStrategyCheck;
import com.mingqijia.gassafety.shared.utils.commonUtils.PageUtil;
import com.mingqijia.gassafety.shared.vcc.VccAuthoritiesProvider;
import com.mingqijia.gassafety.webserver.request.SaveWarnStrategyRequest;
import com.mingqijia.gassafety.webserver.request.StrategyCheckRequest;
import com.mingqijia.gassafety.webserver.request.WarnStrategyCheckListRequest;
import com.mingqijia.gassafety.webserver.request.WarnStrategyPetitionListRequest;
import com.mingqijia.gassafety.webserver.service.WarnStrategyCheckService;
import com.mingqijia.gassafety.webserver.service.WarnStrategyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author guoliang.lao
 * @version 1.0.0
 * @ClassName WarnStrategyController.java
 * @Description 策略审核
 * @createTime 2022年06月21日
 */
@RestController
@Api(tags = "策略诉求审核")
@RequestMapping("/business/v1/warnStrategyCheck")
@Slf4j
public class WarnStrategyCheckController {

    @Autowired
    WarnStrategyCheckService warnStrategyCheckService;
    @Autowired
    WarnStrategyService warnStrategyService;
    @Autowired
    VccAuthoritiesProvider vccAuthoritiesProvider;

    /**
     * 策略审核列表
     *
     * @param request
     * @return
     */
    @PostMapping("getCheckList")
    @ApiOperation(value = "策略审核列表")
    public CommonResponse<PageUtil<WarnStrategyCheck>> getCheckList(@RequestBody WarnStrategyCheckListRequest request) {
        return CommonResponse.success(warnStrategyCheckService.getCheckList(request));
    }

    /**
     * 子公司列表
     * @return
     */
    @GetMapping("getChildSpId")
    @ApiOperation(value = "子公司列表")
    public CommonResponse<cn.hutool.json.JSONObject> getChildSpId() {
        return CommonResponse.success(warnStrategyCheckService.getChildSpId(null));
    }

    /**
     * 策略审核
     *
     * @return
     */
    @PostMapping("strategyCheck")
    @ApiOperation(value = "策略审核")
    public CommonResponse<Object> strategyCheck(@RequestBody @Valid  StrategyCheckRequest request) {
        warnStrategyCheckService.strategyCheck(request);
        return CommonResponse.success(null);
    }

    /**
     * 取消审核
     * @param id
     * @return
     */
    @RequestMapping(value = "cancel", method = RequestMethod.GET)
    @ApiOperation(value = "取消审核")
    public CommonResponse<Object> cancel(@RequestParam @ApiParam(value = "审核记录id") Long id) {
        if (id == null) {
            CommonResponse.failure("id不能为空！");
        }
        warnStrategyCheckService.cancel(id);
        return CommonResponse.success(null);
    }


    @RequestMapping(value = "petition/resubmit", method = RequestMethod.POST)
    @ApiOperation(value = "策略诉求管理-重新提交审核")
    public CommonResponse<Object> resubmit(@RequestBody @Valid SaveWarnStrategyRequest request ) {
        warnStrategyCheckService.resubmit(request);
        return CommonResponse.success(null);
    }

    /**
     * 策略诉求管理列表
     *
     * @param request
     * @return
     */
    @PostMapping("petition/getList")
    @ApiOperation(value = "策略诉求管理-列表")
    public CommonResponse<PageUtil<WarnStrategyCheck>> getAppealList(@RequestBody WarnStrategyPetitionListRequest request) {
        return CommonResponse.success(warnStrategyCheckService.getPetitionList(request));
    }
    /**
     * 查询审核状态下的策略详情
     * @param
     * @return
     */
    @GetMapping("checkStrategyInfo")
    @ApiOperation(value = "查询审核状态下的策略详情")
    public CommonResponse<Object> checkStrategyInfo(@RequestParam("id")@ApiParam(value = "审核记录id") Long id) {
        return CommonResponse.success(warnStrategyService.checkStrategyInfo(id));
    }

}
